clear all

use waves_policy_combined.dta, replace

***Drop missing values***
drop if utility_type==.
drop if disconnected==.
drop if forego_expenses==.
drop if energy_assistance==.
drop if hh_under5==.
drop if hhsize==.
drop if ownhome==.
drop if hh_over65==.

**Encode respondent ID's**
destring caseid_w1, generate(id)
encode utility, generate(utility2)

svyset id [pweight=weight]

sort id wave
xtset id wave
xtdescribe

**Clean variables**
recode gender (2=0)
gen female=0
replace female=1 if gender==0

recode hh_under5 (2=1) (3=1) (4=1)

drop iou muni coop
gen muni=0
replace muni=1 if utility_type==1
gen iou=0
replace iou=1 if utility_type==2
gen coop=0
replace coop=1 if utility_type==3

label define wave_label  1 "Wave 1" 2 "Wave 2" 3 "Wave 3" 4 "Wave 4"
label val wave wave_label

**Generate lags**
gen wap_liheap=0
replace wap_liheap=1 if wap==1 | liheap==1

sort wave id
by wave: gen wapliheap_lag1=wap_liheap[_n-1]

replace stimulus=0 if stimulus==.

sort wave id
by wave: gen stimulus_lag1=stimulus[_n-1]

gen other_assistance=0
replace other_assistance=1 if snap==1 | tanf==1 | medicaid==1 | vet_benefits==1 | unemp_insurance==1

sort wave id
by wave: gen otherassistance_lag1=other_assistance[_n-1]


set scheme s2color

xi i.state
xi i.wave
xi i.utility

*****PAPER MODEL GLOBALS*****
global days_mandatory dayscovered_moratorium wapliheap_lag1 otherassistance_lag1 black hispanic unemployed educ under_100_fpl hh_under5 hhsize ownhome hh_over65 iou coop i.wave i.state

global days_covered dayscovered_total wapliheap_lag1 otherassistance_lag1 black hispanic unemployed educ under_100_fpl hh_under5 hhsize ownhome hh_over65 iou coop i.wave i.state

/*
*****after analysis****
sort wave id
by month: gen moratorium_lag1=covered_moratorium[_n-1]

gen policy_post=0
replace policy_post=1 if moratorium_lag1==1 & covered_moratorium==0

reg disconnected policy_post wapliheap_lag1 otherassistance_lag1 black hispanic unemployed educ under_100_fpl hh_under5 hhsize iou coop i.month i.state
margins, at(policy_post=(0(1)1)) atmeans
marginsplot, xtitle(Covered) ytitle(Probability of Disconnection)


reg utility_debt policy_post wapliheap_lag1 otherassistance_lag1 black hispanic unemployed educ under_100_fpl hh_under5 hhsize iou coop i.month i.state


egen debtmean = mean(utility_debt), by(wave)

tab debtmean

reg utility_debt $days_mandatory [pweight=weight]

*/

****************************
* Attrition Test
****************************

*Attrition inspections (Tables S13)*
sort id
by id: egen wave_count = count(wave)
sort wave_count


**completed all 4 waves**
*Table S13 columns 5 & 6*
by wave_count: sum black hispanic unemployed educ under_100_fpl hh_under5 hhsize ownhome hh_over65

**stopped at wave 2**
*Table S13 columns 1 & 2*
sum black hispanic unemployed educ under_100_fpl hh_under5 hhsize ownhome hh_over65 if wave==2 & wave_count==2

*stopped at wave 3*
*Table S13 columns 3 & 4*
sum black hispanic unemployed educ under_100_fpl hh_under5 hhsize ownhome hh_over65 if wave==3 & wave_count==3
*


**Table S10 Column 1**
reg disconnected $days_mandatory [pweight=weight]
outreg2 using tableS10.rtf, keep($days_mandatory) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) replace

**Table S10 Column 2**
reg disconnected $days_covered [pweight=weight]
outreg2 using tableS10.rtf, keep($days_covered) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

**Table S10 Column 4**
reg forego_expenses $days_mandatory [pweight=weight]
outreg2 using tableS10.rtf, keep($days_mandatory) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

**Table S10 Column 5**
reg forego_expenses $days_covered [pweight=weight]
outreg2 using tableS10.rtf, keep($days_covered) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

**Table S10 Column 7**
reg energy_assistance $days_mandatory [pweight=weight]
outreg2 using tableS10.rtf, keep($days_mandatory) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append

**Table S10 Column 8**
reg energy_assistance $days_covered [pweight=weight]
outreg2 using tableS10.rtf, keep($days_covered) stats(coef se) alpha(0.01, 0.05, 0.1) dec(3) pdec(3) append
